<?php
include_once '../inc/config.inc.php';
include_once '../inc/mysql.inc.php';
include_once 'inc/tool.inc.php';
$link=connect();
include_once 'inc/is_manage_login.inc.php';//验证管理员是否登录

if(isset($_POST['submit'])){
	//转义入库
	//$_POST=escape($link,$_POST);

	$query="insert into data(title,Identification,content,time) values('{$_POST['title']}','{$_POST['Identification']}','{$_POST['content']}',now())";
	execute($link,$query);
	if(mysqli_affected_rows($link)==1){
		skip('data.php','ok','恭喜你，添加成功！');
	}else{
		skip('data_add.php','error','对不起，添加失败，请重试！');
	}
}

if(!isset($_GET['id']) || !is_numeric($_GET['id'])){
	skip('data_add.php','error','id参数错误！');
}

$query="select * from data where id={$_GET['id']}";
$result=execute($link,$query);
$data=mysqli_fetch_assoc($result);

$template['title']='数据添加页';
$template['css']=array('style/public.css');
?>
<?php include 'inc/header.inc.php'?>
<div id="main">
	<div class="title" style="margin-bottom:20px;">添加数据</div>
	<form method="post">
		<table class="au">
			<tr>
				<td>标题</td>
				<td><input name="title" maxlength="30" required="required" placeholder="请输入标题" value=" <?php echo $data['title']?>" type="text" /></td>
				<td>
					标题不得为空,标题不得超过30个字符
				</td>
			</tr>
			<tr>
				<td>标识串</td>
				<td><input name="Identification" maxlength="25" required="required" placeholder="请输入标识串" type="text" value="<?php echo $data['Identification']?>" /></td>
				<td>
					标识串不得超过25位
				</td>
			</tr>
			<tr>
				<td>详细内容</td>
				<td><textarea name="content" required="required" placeholder="请输入详细内容" maxlength="200"><?php echo $data['content']?></textarea></td>
				<td>
					详细内容不得为空
				</td>
			</tr>
		</table>
		<input style="margin-top:20px;cursor:pointer;" class="btn" type="submit" name="submit" value="添加" />
	</form>
</div>
<?php include 'inc/footer.inc.php'; close($link);?>